import tkinter as tk
from ui import FocusUI
from timer import Timer
from config import ConfigManager
from logger import setup_logger


def main():
    # 初始化日志系统
    logger = setup_logger()
    logger.info('Application started')

    # 加载配置
    config = ConfigManager('config.json')

    # 初始化主窗口
    root = tk.Tk()
    root.title('Focus Helper')
    app = FocusUI(root, config, logger)

    # 初始化计时模块
    timer = Timer(app.update_timer_display, config, logger)
    timer.set_completion_callback(app.trigger_alert)
    timer.set_reminder_callback(None)
    app.set_timer(timer)

    logger.info(f'========='*4+ 'Application closed'+'========='*4) # 将日志记录移到 FocusUI 类的 on_close 方法中统一处理
    root.mainloop()


if __name__ == '__main__':
    main()
